package com.example.smartcity_40.Outpatient;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;

import android.content.Intent;
import android.os.Bundle;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.smartcity_40.Outpatient.bean.HospitaldetailsBean;
import com.example.smartcity_40.Outpatient.bean.MediclistBean;
import com.example.smartcity_40.R;
import com.example.smartcity_40.tool.Tool;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

public class HospitaldetailsActivity extends AppCompatActivity {

    private HospitaldetailsActivity context;
    private Tool tool;
    private String hospitalid;
    private ImageView imgUrl;
    private TextView brief;
    private TextView name;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hospitaldetails);
        context = this;
        initview();
        sendHospitaldetails();
    }

    private void sendHospitaldetails() {
        tool.send("/prod-api/api/hospital/hospital/"+hospitalid,
                Tool.GET,
                null,
                false,
                HospitaldetailsBean.class, new Function1<HospitaldetailsBean, Unit>() {
                    @Override
                    public Unit invoke(HospitaldetailsBean hospitaldetailsBean) {
                        try {
                            HospitaldetailsBean.DataBean data = hospitaldetailsBean.getData();
                            String hospitalName = data.getHospitalName();
                            if(!TextUtils.isEmpty(hospitalName)){
                                name.setText(hospitalName);
                            }

                            String dataBrief = data.getBrief();
                            if(!TextUtils.isEmpty(dataBrief)){
                                brief.setText(Html.fromHtml(dataBrief).toString());
                            }

                            String dataImgUrl = data.getImgUrl();
                            if(!TextUtils.isEmpty(dataImgUrl)){
                                Glide.with(context).load(Tool.url+dataImgUrl).into(imgUrl);
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }
                });
    }

    private void initview() {
        Intent intent = getIntent();
        hospitalid = intent.getStringExtra("hospitalid");

        ImageView back = findViewById(R.id.back);
        imgUrl = findViewById(R.id.imgUrl);
        brief = findViewById(R.id.brief);
        name = findViewById(R.id.name);
        TextView register = findViewById(R.id.register);
        tool = new Tool(context);
        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.finish();
            }
        });


        register.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,RegisterActivity.class);
                context.startActivity(intent);
            }
        });
    }
}